home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / gamesmaster / source / c / sprites.c < prev   
Encoding:
C/C++ Source or Header  |  1996-09-13  |  3.4 KB  |  107 lines

  1. /*
  2. ** Sprite example
  3. ** --------------
  4. ** This example shows you how to set up a 16 colour OCS sprite with a
  5. ** doubled X axis (32 pixels width).  Those with hardware experience will
  6. ** know that it takes 4 sprite banks to do this successfully in OCS, which
  7. ** leaves you with another 4 banks to do with what you will.  You can do
  8. ** this same demo in AGA with just 2 banks used.
  9. ** 
  10. ** The sprite is attached to the mouse, so try moving it around a bit.
  11. */
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15.  
  16. #include <exec/types.h>
  17. #include <exec/memory.h>
  18. #include <games/games.h>
  19. #include <proto/games.h>
  20. #include <proto/exec.h>
  21.  
  22. struct GMSBase *GMSBase;
  23. UWORD  Timer;
  24. APTR   SprMemBase;
  25. ULONG  ZBXY;
  26.  
  27. struct Sprite Sprite0 = {
  28.    SPV1,                     /* Version number */
  29.    0,                        /* Bank Number 0 */
  30.    0,                        /* Ptr to graphic */
  31.    100,100,                  /* Beginning X/Y positions */
  32.    0,                        /* Current frame */
  33.    16,21,                    /* Width, Height */
  34.    16,                       /* Amt of colours */
  35.    16,                       /* Colour start in palette */
  36.    2,                        /* Amt of planes */
  37.    LORES|XLONG,              /* Resolution attributes */
  38.    0,                        /* Position in relation to playfields */
  39.    0,0                       /* Private */
  40. };
  41.  
  42. UWORD Palette[] = {
  43.    0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  44.    0x0000,0x0688,0x0466,0x0344,0x0CC0,0x0980,0x0870,0x0650,
  45.    0x01C2,0x0050,0x0B0B,0x0606,0x0F20,0x0910,0x0BBB,0x0FFF,
  46.    0x00BF,0x0068,0x0568,0x09BF,0x0FF0,0x0EE0,0x0BA0,0x0540
  47. };
  48.  
  49. struct GameScreen GameScreen = {
  50.    GSV1,                     /* GameScreen Version */
  51.    0,0,0,                    /* Screen_Mem1,2,3 */
  52.    0,                        /* ScreenLink */
  53.    &Palette,                 /* Address of Palette */
  54.    0,                        /* Address of RasterList */
  55.    32,                       /* Amount of colours */
  56.    320,256,320,256,          /* Screen & Pic Height/Width */
  57.    1,                        /* Amt_Planes */
  58.    0,0,                      /* Top Of Screen, X/Y */
  59.    0,0,                      /* X/Y pic offsets */
  60.    SPRITES|NOSPRBDR,         /* Special attributes */
  61.    LORES,                    /* Screen mode */
  62.    INTERLEAVED,              /* Screen type */
  63.    0                         /* Reserved */
  64. };
  65.  
  66. struct GameScreen *OurScreen = &GameScreen;
  67. struct Sprite *Sparkie = &Sprite0;
  68.  
  69. /*=========================================================================*/
  70.  
  71. void main(void)
  72. {
  73.    struct GamesLibrary *GMSBase = (struct GamesLibrary *)
  74.        OpenLibrary("games.library", 0);
  75.    if (GMSBase == NULL) exit(FALSE);
  76.  
  77.    SetUserPri();
  78.    Sparkie->Data = SmartLoad("GAMESLIB:data/Sparkie.raw",0,0,MEMF_CHIP);
  79.  
  80.    if (Add_Screen(OurScreen) == NULL) {
  81.       Init_Sprite(OurScreen,Sparkie);
  82.       Update_Sprite(OurScreen,Sparkie);
  83.       Show_Screen(OurScreen);
  84.  
  85.       ZBXY = Read_Mouse(JPORT1);         /* Initialise the mouse port */
  86.  
  87.       while (!(ZBXY&MB_LMB)) {
  88.  
  89.          if (++Timer&0x1) {
  90.             if (Sparkie->Frame == 5) Sparkie->Frame = 0;
  91.             else Sparkie->Frame++;
  92.          }
  93.  
  94.          ZBXY = Read_Mouse(JPORT1);
  95.          Sparkie->XPos += (BYTE)(ZBXY>>8);
  96.          Sparkie->YPos += (BYTE)ZBXY;
  97.          Wait_OSVBL();
  98.          Update_Sprite(OurScreen, Sparkie);
  99.       }
  100.    }
  101.  
  102.    FreeMemBlock(Sparkie->Data);
  103.    Delete_Screen(OurScreen);
  104.    CloseLibrary((struct Library *)GMSBase);
  105. }
  106.  
  107.